package com.ruoyi.project.hissystem.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.hissystem.domain.RegistraFee;
import com.ruoyi.project.hissystem.service.IHisRegistraFeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : 高向前
 * @date : 15:27 2021/8/18
 */
@RestController
@RequestMapping("/hissystem/registraFee")
public class RegistraFeeController extends BaseController {
    @Autowired
    private IHisRegistraFeeService hisregistraFeeService;


    //查询所有
    @PreAuthorize("@ss.hasPermi('hissystem:registraFee:list')")
    @GetMapping("/list")
    public TableDataInfo list(RegistraFee registraFee){
        startPage();
        List<RegistraFee> projectFeeList = hisregistraFeeService.listRegistraFee(registraFee);
        return getDataTable(projectFeeList);
    }

    //新增项目费用
    @Log(title = "项目费用管理", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('hissystem:registraFee:add')")
    @PostMapping("/addRegistraFee")
    public AjaxResult addRegistraFee(@RequestBody RegistraFee registraFee){
        registraFee.setCreateBy(SecurityUtils.getUsername());
        int rows = hisregistraFeeService.addRegistraFee(registraFee);
        return toAjax(rows);
    }


    //修改项目费用之前根据Id查询
    @PreAuthorize("@ss.hasPermi('hissystem:registraFee:update')")
    @GetMapping("/{registraFeeId}")
    public AjaxResult selectRegistraFeeById(@PathVariable int registraFeeId){
        RegistraFee registraFee = hisregistraFeeService.selectRegistraFeeById(registraFeeId);
        return AjaxResult.success(registraFee);
    }

    //修改项目费用
    @Log(title = "项目费用管理", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('hissystem:registraFee:update')")
    @PutMapping("/updateRegistraFee")
    public AjaxResult updateRegistraFee(@RequestBody RegistraFee registraFee){
        int rows = hisregistraFeeService.updateRegistraFee(registraFee);
        return toAjax(rows);
    }

    //删除项目费用
    @Log(title = "项目费用管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{registraFeeIds}")
    @PreAuthorize("@ss.hasPermi('hissystem:registraFee:remove')")
    public AjaxResult deleteRegistraFees(@PathVariable int[] registraFeeIds){
        return toAjax(hisregistraFeeService.deleteRegistraFees(registraFeeIds));
    }
}
